package com.mjf.cjt.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mjf.cjt.domain.TFsaler;
import com.mjf.cjt.mapper.TFsalerMapper;
import com.mjf.cjt.service.AsyncTMService;
import com.mjf.cjt.service.TFsalerService;
import com.mjf.cjt.vo.TFPersonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * desc
 * </p>
 *
 * @author chenshoumeng
 * @date 2025/5/21 13:27
 */
@Service
public class TFsalerServiceImpl extends ServiceImpl<TFsalerMapper, TFsaler> implements TFsalerService {

    @Autowired
    private AsyncTMService asyncTMService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void asyncYG() {
        List<TFPersonVO> tfPersonVOS = asyncTMService.asyncYG();
        if (CollectionUtil.isEmpty(tfPersonVOS)) {
            return;
        }
        List<TFsaler> tfSalers = new ArrayList<>();
        for (TFPersonVO tfPersonVO : tfPersonVOS) {
            TFsaler tfSaler = new TFsaler();
            tfSaler.setSaid(tfPersonVO.getId());
            tfSaler.setSacode(tfPersonVO.getCode());
            tfSaler.setSaname(tfPersonVO.getName());
            tfSalers.add(tfSaler);
        }
        saveOrUpdateBatch(tfSalers);
    }
}
